import ika
import direction
import engine
import resources
from map_entity import MapEntity
import random

class Enemy(MapEntity):
    def __init__(self, x, y, layer, filename):
        MapEntity.__init__(self, x, y, layer, filename)


class EnemyVillager(Enemy):
    # TODO: Make villager do something cool instead of a retarded pong-like bounce
    health = max_health = 4
    move_timer = 0
    mindlessly_pausing = False
    
    def __init__(self, x, y, layer, filename):
        Enemy.__init__(self, x, y, layer, filename)
        self.x_speed = -1.0
        self.y_speed = -1.0
        
    def Update(self):        
        if self.dead:
            return
        
        if not self.mindlessly_pausing:
            if self.direction == direction.left:
                self.x_speed = -1.0
                self.y_speed = 0
            elif self.direction == direction.right:
                self.x_speed = 1.0
                self.y_speed = 0
            elif self.direction == direction.up:
                self.x_speed = 0
                self.y_speed = -1.0
            elif self.direction == direction.down:
                self.x_speed = 0
                self.y_speed = 1.0
        else:
            self.x_speed = 0
            self.y_speed = 0
        
        self.move_timer -= 1
        if self.was_obstructed or self.move_timer <= 0:
            if self.mindlessly_pausing:
                self.mindlessly_pausing = False
                self.move_timer = ika.Random(30, 50)
            else:
                r = ika.Random(0, 4)
                self.move_timer = 10
                d = self.direction
                if r == 0:
                    self.direction = direction.left
                elif r == 1:
                    self.direction = direction.right
                elif r == 2:
                    self.direction = direction.up
                elif r == 3:
                    self.direction = direction.down
                if d != self.direction:
                    self.mindlessly_pausing = True
        
        super(EnemyVillager, self).Update()
                
                
                
                